package Common;

import java.util.Map;
import java.util.HashMap;

public class Errors
{

    private static final Map<String, String> Fatal = new HashMap<String, String>();
    private static final Map<String, String> Serious = new HashMap<String, String>();
    private static final Map<String, String> Warning = new HashMap<String, String>();


    static
    {
        Fatal.put("InvalidStart", "Fatal error: Assembly has stopped (Invalid start directive");
        Fatal.put("InvalidFirstLine", "Syntax requires the first line o be");
        Fatal.put("InvalidSymbolCount", "use less labels!");
        Fatal.put("InvalidLineCount", "make your program more consise");

        Serious.put("InvalidFunction", "User has entered an invalid function code");
        Serious.put("InvalidLabel", "Labels must be a-z, A-Z, and 0-9 after the first character. 32 character max");
        Serious.put("InvalidOperation", "Use one of the valid 16 instructions. substitued MOPER ADD,=0");
        Serious.put("InvalidSField", "must be a valid defined label or a number in the range of 0 to 1023.");
        Serious.put("InvalidLiteral", "MOPER ADD,=0 substituted literal must be an integer value between -32768 to +32767");
        Serious.put("InvalidRLabel", "rlabel was found to be invalid. Check syntax rules");
        Serious.put("InvalidCommaCount", "MOPER ADD,=0 substituted remove erroneous commas");
        Serious.put("InvalidDirectiveRange", "operand must be in the range 0 to 1023 or an equated symbol with the same range");
        Serious.put("InvalidDirectiveLabel", "line ignored");
        Serious.put("InvalidDatVal", "dat 0 substituted. Must be in integer range -32768 to +32767");
        Serious.put("InvalidNullLabel", "no label is expected here");
        Serious.put("InvalidExpressionOpCount", "There may be no more than three operators in an expression");
        Serious.put("InvalidEQULabel", "EQU may only contain numbers and valid, already defined EQU labels");
        Serious.put("InvalidDuplicateLabel", "Label already defined previously in the program. Cannot redefine labels");
        Serious.put("InvalidUndefinedLabel", "Label has not been defined in the program");
        Serious.put("InvalidADCCount", "ADC may have at most two elements in the operand");
        Serious.put("InvalidReset", "Reset may only change the line count to a value between the current line count and 1023. NOP substituted");
        Serious.put("InvalidExpression", "Expression is invalid");
        Serious.put("InvalidADCAddress", "ADC must reference a memory location within this program");

        Warning.put("InvalidBlankLine", "please remove blank lines");
        Warning.put("InvalidExtrnEntryField", "line ignored");
        Warning.put("InvalidComment", "comment field starts with \":\" and must be an alphanumeric string");
    }

    public static boolean ReplaceWithNOP(String error)
    {
        if (error.equals("InvalidOperation")
            || error.equals("InvalidSField")
            || error.equals("InvalidLiteral")
            || error.equals("InvalidCommaCount")
            || error.equals("InvalidReset")
            || error.equals("InvalidFunction"))
            return true;

        return false;
    }

    public static String GetErrorMessage(String cond)
    {
        if (Fatal.containsKey(cond))
        {
            return Fatal.get(cond);
        }
        else if (Serious.containsKey(cond))
        {
            return Serious.get(cond);
        }
        else if (Warning.containsKey(cond))
        {
            return Warning.get(cond);
        }

        //sets default value. Used to make sure the error is found in the maps or notify that error is not defined yet
        return "No error description found for " + cond;
    }
}
